#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Project: spd-sxmcc
"""
@author: lyndon
@time Created on 2018/11/19 23:48
@desc
"""

from bs4 import BeautifulSoup

html = "<ul class='country'><li>中国</li><li>美国</li></ul>"
# 解析html然后得到一个soup文档
soup = BeautifulSoup(html, 'html.parser')
html = soup.prettify()
ul = soup.find('ul', attrs={'class': 'country'})

# 下面代码只返回一个匹配的元素
print(ul.find('li'))  # returns the first match element
print('-----------------------------------')
# 下面代码返回又有匹配的元素
for countryname in ul.find_all('li'):
    print(countryname)
